<template>
  <el-dialog
    draggable
    ref="dialogRef"
    align-center
    destroy-on-close
    :width="width"
    :show-close="false"
    v-model="openDialog"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    class="pub-dialog"
    :append-to-body="modalAppendToBody"
    :fullscreen="fullscreen"
    :top="top"
    @close="closeDialog"
  >
    <div class="modal-content">
      <div class="title flex items-center justify-between">
        <div class="title-text">
          <div class="text font-alipuhui text-14px font-bold">
            {{ props.title }}
          </div>
          <div class="extra"></div>
        </div>
        <div class="close-btn flex cursor-pointer" @click="closeDialog">
          <el-icon :size="22" color="#333">
            <Close />
          </el-icon>
        </div>
      </div>
      <!--  -->
      <div
        class="content cus-scroll-y p-15px"
        :class="'hasExtraBtn' + hasExtraBtn"
      >
        <slot />
      </div>
      <!--  -->
      <div class="footer flex items-center justify-center" v-if="!hasExtraBtn">
        <el-button type="primary" size="small" @click="closeDialog">
          关闭
        </el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script setup>
import { ElDialog } from 'element-plus'
import { Close } from '@element-plus/icons-vue'
const emit = defineEmits(['update:visible','close'])
const props = defineProps({
  title: {
    type: String,
    default: '弹框标题'
  },
  visible: {
    type: Boolean,
    default: false
  },
  width: {
    type: [String],
    default: '50%'
  },
  modalAppendToBody: {
    type: Boolean,
    default: true
  },
  fullscreen: {
    type: Boolean,
    default: false
  },
  top: {
    type: String,
    default: '20vh'
  },
  showClose: {
    type: Boolean,
    default: false
  },
  hasExtraBtn: {
    type: Boolean,
    default: false
  }
})
const extraBtnSlot = !!useSlots().extraBtn
const dialogRef = ref(null)
const openDialog = computed({
  get() {
    return props.visible
  },
  set(val) {
    emit('update:visible', val)
  }
})
const closeDialog = () => {
  emit('update:visible', false)
  emit('close')
}
</script>

<style lang="scss" scoped>
.modal-content {
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  .title {
    background-color: rgb(250, 250, 252);
    height: 45px;
    padding: 0 10px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
  }

  .content {
    max-height: 80vh;
    background-color: white;
    &.hasExtraBtntrue {
      padding-bottom: 55px;
    }
    // padding-bottom: 50px;
  }

  .footer {
    background-color: rgb(250, 250, 252);
    height: 45px;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    padding: 0 10px;
    :deep(.n-button) {
      margin-right: 10px;
    }
  }
}
:deep(.el-loading-parent--relative) {
  position: inherit !important;
}
</style>
